package cn.exrick.xboot.modules.biddataproject.controller;

import cn.exrick.xboot.common.utils.ResultUtil;
import cn.exrick.xboot.common.vo.Result;
import cn.exrick.xboot.modules.bicmktbiddinginfo.entity.BidAndBidBack;
import cn.exrick.xboot.modules.biddataproject.entity.BidDeptProvince;
import cn.exrick.xboot.modules.biddataproject.service.BidDeptProvinceService;
import com.baomidou.dynamic.datasource.annotation.DS;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 合同金额按部门省份分类
 * @author 王延超
 */
@Slf4j
@RestController
@DS("other")
@Api(tags = "合同金额按部门省份分类接口")
@RequestMapping("/xboot/bidDeptProvince")
@Transactional
public class BidDeptProvinceController {
    @Autowired
    private BidDeptProvinceService bidDeptProvinceService;


    //分年投中标数据
    @RequestMapping(value = "/getNianContract/{v}", method = RequestMethod.GET)
    @ApiOperation(value = "年为单位")
    public Result getSanNianContract(@PathVariable String v){
        List<BidDeptProvince> list = new ArrayList<>();
        if (v.equals("1")) {
            list = bidDeptProvinceService.getYearContractlnfo(2024);
        }else if (v.equals("2")){
            list = bidDeptProvinceService.getYearContractlnfo(2023);
        }else if (v.equals("3")){
            list = bidDeptProvinceService.getYearContractlnfo(2022);
        }
        HashMap<String, Object> map = new HashMap<>();
        List<Object> list1 = new ArrayList<>();
        List<Object> list2 = new ArrayList<>();
        List<Object> list3 = new ArrayList<>();
        for (BidDeptProvince bidAndBidBack: list) {
            list1.add(bidAndBidBack.getDeptName());
            list2.add(bidAndBidBack.getBidNumber());
            list3.add(bidAndBidBack.getBidMoney());
        }
        map.put("l0",list);
        map.put("l1",list1);
        map.put("l2",list2);
        map.put("l3",list3);
        return ResultUtil.data(map);
    }

    //年为单位
    @RequestMapping(value = "/getShengFenYear", method = RequestMethod.GET)
    @ApiOperation(value = "省内中标投标金额数量")
    public Result getShanDongBidding(){
        //中投标数量金额本年
        Map<String, Object> stringObjectMap = bidDeptProvinceService.BidAndBidBackNumberAndMoneyByYear();
        return ResultUtil.data(stringObjectMap);
    }
    //月为单位
    @RequestMapping(value = "/getShengFenM", method = RequestMethod.GET)
    @ApiOperation(value = "省内中标投标金额数量")
    public Result getShengFenM(){
        //中投标数量金额本年
        Map<String, Object> stringObjectMap = bidDeptProvinceService.BidAndBidBackNumberAndMoneyByM();
        return ResultUtil.data(stringObjectMap);
    }
}
